﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;

namespace LybrixNursingCRMDesktop.CustomControls
{
    /// <summary>
    /// Interaction logic for SearchTextBox.xaml
    /// </summary>
    public partial class SearchTextBox : UserControl
    {
        private bool isDoubleSize;
        private bool isInvalid;


        public event EventHandler TextChanged;

        private void txtBoxValue_TextChanged(object sender, TextChangedEventArgs e)
        {
            if (TextChanged != null)
            {
                TextChanged(this, EventArgs.Empty);
            }
        }

        #region Construcotors

        public SearchTextBox()
        {
            InitializeComponent();
            txtBoxValue.BorderBrush = Brushes.Gray;
        }


        public SearchTextBox(List<string> _valueList)
        {
            InitializeComponent();
            txtBoxValue.BorderBrush = Brushes.Gray;
        }

        #endregion

        #region Properties

        public string FieldID { get; set; }

        public string Text
        {
            get { return txtBoxValue.Text; }
            set { txtBoxValue.Text = value; }
        }

        public bool IsEnabled
        {
            set
            {
                txtBoxValue.IsEnabled = value;
                if (value == false)
                    txtBoxValue.Background = Brushes.LightGray;
                else
                    txtBoxValue.Background = Brushes.White;
            }
        }

        public bool IsDoubleSize
        {
            get { return isDoubleSize; }
            set
            {
                isDoubleSize = value;
                if (isDoubleSize)
                {
                    txtBoxValue.Width = 380;
                }
                else
                {
                    txtBoxValue.Width = 150;
                }
            }
        }

        public void IsMissed(bool value)
        {
            if (value)
            {
                txtBoxValue.Background = Brushes.Gold;
                txtBoxValue.ToolTip = "Missing Field";
            }
            else
            {
                txtBoxValue.Background = Brushes.White;
                txtBoxValue.ToolTip = "";
            }
        }
        #endregion

        #region Public

        public bool IsInvalid
        {
            get { return isInvalid; }
            set
            {
                if (value)
                {
                    txtBoxValue.BorderBrush = Brushes.Red;
                    txtBoxValue.BorderThickness = new Thickness(2);
                }
                else
                {
                    txtBoxValue.BorderBrush = Brushes.Gray;
                    txtBoxValue.BorderThickness = new Thickness(1);
                }
                isInvalid = value;
            }
        }

        public void ClearValue()
        {
            txtBoxValue.Text = "";
        }

        public void SetFocus()
        {
            txtBoxValue.Focus();
        }

        public void SelectAll()
        {
            txtBoxValue.SelectAll();
        }

        public string GetValue()
        {
            return (txtBoxValue.Text);
        }

        #endregion
    }
}
